<template>
  <!-- 是否确认提交？ -->
  <a-modal :visible="visible" title="提醒!" @cancel="cancelBtn">
    <a-spin :spinning="flowChartLoading">
    <p>是否确认提交？</p>
    <a-form-model ref="ruleForm" :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }" :rules="rules">
      <a-form-model-item label="是否加急" prop="urgent" class="requiredFormItem">
        <a-select v-model="form.urgent">
          <a-select-option value="2"> 是 </a-select-option>
          <a-select-option value="1"> 否 </a-select-option>
        </a-select>
      </a-form-model-item>
    </a-form-model>
    </a-spin>
    <div slot="footer">
      <a-button @click="cancelBtn" :loading="flowChartLoading">取消</a-button>
      <a-button type="primary" @click="handleOk" :loading="flowChartLoading">提交</a-button>
    </div>
  </a-modal>
</template>
<script>
import { updateVariables,deleteProcessByBusinessId} from '@/api/indexPage'
export default {
  name: 'specified',
  props: {
    // 模态框显示隐藏
    visible: {
      type: Boolean,
      default: false
    },
    businessId: {
      type: String,
      default: ''
    },
     //是否关闭上级页面
    isCloseUpper: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      form: {
        urgent: '1'
      },
      rules: {
        urgent: [{ required: true, message: '请选择是否加急', trigger: 'blur' }]
      },
      flowChartLoading:false
    }
  },
  watch: {},
  mounted() {},
  methods: {
    handleOk() {
      let req = {
        variables: {}
      }
      req.businessId = this.businessId
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          req.urge = this.form.urgent * 1 === 2 ? true : false
          updateVariables(req).then((res) => {
            if (res.status == 200) {
                this.$message.success('提交成功！')
              // 追加自定义事件 不改原有逻辑 可以不受限制 想怎么处理 就怎么处理
              this.$emit("closeDialog")
               if (this.isCloseUpper) {
                 this.$emit('closevisible')
                this.$multiTab.close()
              } else {
                this.$emit('submitUrgent')
                this.$emit('close',true)// 会触发爷组件的submit事件
              }
                }
          })
        } else {
          this.$message.warning("请填写完所有必填项信息")
        }
      })
    },
    cancelBtn() {
        let that = this
        this.$confirm({
        title: '温馨提示',
        content: '确定要取消审批？',
        onOk: () => {
          that.flowChartLoading = true;
         deleteProcessByBusinessId(this.businessId).then((res)=>{
          if(res.status===200){
             that.flowChartLoading  = false
            this.$message.success('取消成功！');
            // 追加自定义事件 不改原有逻辑 可以不受限制 想怎么处理 就怎么处理
            this.$emit("closeDialog")
               if(that.isCloseUpper){
                 that.$emit('closevisible')
                that.$multiTab.close()
              }else{
                console.log(333333333)
                that.$emit('close',false); // 会触发爷组件的submit事件
                that.$emit('closevisible')
              }
              }
            })
          },
          onCancel() {
            that.$emit('close',false) // 会触发爷组件的submit事件
          }
        })
    }
  }
}
</script>
